package com.haidechizi.leetcode;

import java.util.LinkedList;
import java.util.Queue;

/**
 * @author: wangdejun
 * @create: 2020-04-10 10:37
 **/
public class _3_无重复字符的最长子串 {

    public int lengthOfLongestSubstring(String s) {
        if (s == null || "".equals(s)) {
            return 0;
        }
        Queue<Character> queue = new LinkedList<>();
        char[] chars = s.toCharArray();
        int i = 0;
        int max = 1;
        while (i < chars.length) {
            while (queue.contains(chars[i])) {
                queue.poll();
            }
            queue.add(chars[i]);
            i++;
            max = Math.max(max, queue.size());
        }
        return max;
    }
}
